// Copyright 2013 Google Inc. All Rights Reserved.auto

#include <errno.h>
#include <irt_syscalls.h>
#include <sys/socket.h>

int getsockname(int s, struct sockaddr *address, socklen_t *len) {
  ENOSYS_IF_NULL(__nacl_irt_getsockname)

  struct nacl_abi_sockaddr na_address;
  size_t na_len;

  int result = __nacl_irt_getsockname(s, &na_address, &na_len);
  if (result != 0) {
    errno = __nacl_abi_errno_to_errno(result);
    return -1;
  }

  __nacl_abi_sockaddr_to_sockaddr(&na_address, na_len, address, len);
  return 0;
}


